package com.zhou.bjgl.bjgl.business_web.controller;


import com.zhou.bjgl.bjgl.myAnnotations.UserLoginToken;
import com.zhou.bjgl.bjgl.req.BaseModel;
import com.zhou.bjgl.bjgl.req.b_sign.BSigningChartsReq;
import com.zhou.bjgl.bjgl.req.b_sign.BSigningQueryReq;
import com.zhou.bjgl.bjgl.resp.sgin.BSigningResp;
import com.zhou.bjgl.bjgl.resp.PageResp;
import com.zhou.bjgl.bjgl.resp.common.ApiRestResponse;
import com.zhou.bjgl.bjgl.business_web.service.BSigningService;
import com.zhou.bjgl.bjgl.resp.sgin.SginGraphicResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  签到模块
 * </p>
 *
 * @author jz
 * @since 2021-07-04
 */
@RestController
@RequestMapping("/bjgl/b-signing")
@Api("签到管理")
public class BSigningController extends BaseModel {

    @Resource
    private BSigningService bSigningService;

    @ApiOperation("签到")
    @PostMapping("/check")
    @UserLoginToken
    public ApiRestResponse checkInClass(@RequestBody BSigningQueryReq req) {
        bSigningService.checkInClass(req);
        return ApiRestResponse.success("签到成功");
    }

    @ApiOperation("签到列表")
    @GetMapping("/list")
    @UserLoginToken
    public ApiRestResponse sginList(BSigningQueryReq req) {
        PageResp<BSigningResp> signingResps=bSigningService.getCheckList(req);
        return ApiRestResponse.success(signingResps);
    }

    @ApiOperation("未签到列表")
    @GetMapping("/getNotSginList")
    @UserLoginToken
    public ApiRestResponse NotSginList(BSigningQueryReq req) {
        PageResp<BSigningResp> signingResps=bSigningService.getNotCheckList(req);
        return ApiRestResponse.success(signingResps);
    }

    @ApiOperation("获取图示数据")
    @GetMapping("/getSginGraphic")
    @UserLoginToken
    public ApiRestResponse getSginGraphic(BSigningQueryReq req) {
        req.setPage(1);
        req.setSize(0);
        PageResp<BSigningResp> signingResps=bSigningService.getCheckList(req);
        PageResp<BSigningResp> notCheckResps = bSigningService.getNotCheckList(req);

        //构造结构数据
        SginGraphicResp alreadySginGraphicResp = new SginGraphicResp();
        alreadySginGraphicResp.setValue(signingResps.getTotal()).setName("已签到");
        SginGraphicResp notSginGraphicResp = new SginGraphicResp();
        notSginGraphicResp.setValue(notCheckResps.getTotal()).setName("未签到");

        ArrayList<SginGraphicResp> sginGraphicResps = new ArrayList<>();
        sginGraphicResps.add(alreadySginGraphicResp);
        sginGraphicResps.add(notSginGraphicResp);
        return ApiRestResponse.success(sginGraphicResps);
    }

    @ApiOperation("按日期统计签到")
    @GetMapping("/statisticalCheck")
    @UserLoginToken
    public ApiRestResponse statisticalCheck(BSigningChartsReq bSigningChartsReq){
        bSigningChartsReq.setClassId(threadLocal.get().getClassId());
        HashMap<String, List> chartResult=bSigningService.getChartsDate(bSigningChartsReq);
        return ApiRestResponse.success(chartResult);
    }
}

